﻿@model LanguageModel
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)

<div id="language-edit">
    <ul>
        <li @Html.RenderSelectedTabIndex(0, GetSelectedTabIndex())>
            @T("Admin.Configuration.Languages.Info")
        </li>
        <li @Html.RenderSelectedTabIndex(1, GetSelectedTabIndex())>
            @T("Admin.Configuration.Languages.Stores")
        </li>
    </ul>
    <div>
        @TabInfo()
    </div>
    <div>
        @TabStores()
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#language-edit").kendoTabStrip({
            animation: {
                open: {
                    effects: "fadeIn"
                }
            },
            select: tabstrip_on_tab_select
        });
    });
</script>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "language-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}


@*save selected tab index*@
<input type="hidden" id="selected-tab-index" name="selected-tab-index" value="@(GetSelectedTabIndex())">

@helper TabInfo()
{
    <script type="text/javascript">
        function toggleFlags() {
            $('#pnlAllFlags').toggle();
            if ($('#pnlAllFlags').css('display') == 'none') {
                $('#displayAllFlags').html('@T("Admin.Common.Show")');
            }
            else {
                $('#displayAllFlags').html('@T("Admin.Common.Hide")');
            }
        }
    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Name):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LanguageCulture):
            </td>
            <td class="adminData">
                 @{
                    var cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures)
                        .OrderBy(x => x.EnglishName)
                        .Select(x => new SelectListItem()
                                         {
                                             Value = x.IetfLanguageTag,
                                             Text = string.Format("{0}. {1}", x.EnglishName, x.IetfLanguageTag)
                                         });
                }
                @Html.DropDownListFor(model => model.LanguageCulture, cultures)
                @Html.ValidationMessageFor(model => model.LanguageCulture)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.UniqueSeoCode):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.UniqueSeoCode)
                @Html.ValidationMessageFor(model => model.UniqueSeoCode)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.FlagImageFileName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.FlagImageFileName)
                @Html.ValidationMessageFor(model => model.FlagImageFileName)
                <br/>
                <a id="displayAllFlags" href="javascript:toggleFlags();">@T("Admin.Common.Show")</a>
                <div id="pnlAllFlags" style="display: none">
                    @foreach (var fileName in Model.FlagFileNames)
                    {
                        <img alt="" src="@Url.Content("~/Content/Images/flags/" + fileName)"/>
                        @fileName
                        <text>, </text>
                    }
                </div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Rtl):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Rtl)
                @Html.ValidationMessageFor(model => model.Rtl)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Published):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Published)
                @Html.ValidationMessageFor(model => model.Published)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.DisplayOrder):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.DisplayOrder)
                @Html.ValidationMessageFor(model => model.DisplayOrder)
            </td>
        </tr>
    </table>
}
@helper TabStores()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToStores)").click(toggleStoreMapping);

            toggleStoreMapping();
        });


        function toggleStoreMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToStores)').is(':checked')) {
                $('#pnl-available-stores').show();
            }
            else {
                $('#pnl-available-stores').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LimitedToStores):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToStores)
                @Html.ValidationMessageFor(model => model.LimitedToStores)
            </td>
        </tr>
        <tr id="pnl-available-stores">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AvailableStores):
            </td>
            <td class="adminData">
                @if (Model.AvailableStores != null && Model.AvailableStores.Count > 0)
                {
                    foreach (var store in Model.AvailableStores)
                    {
                    <div>
                        <input type="checkbox" name="SelectedStoreIds" value="@store.Id" checked="@(Model.SelectedStoreIds != null && Model.SelectedStoreIds.Contains(store.Id))" />@store.Name
                    </div>
                    }
                }
                else
                {
                    <div>No stores defined</div>
                }</td>
        </tr>
    </table>
}
